<?php

class Controller_Manager_Site extends Controller
{
    public function __construct()
    {
        $aUser = getCurrentUser();
		if (!isset($aUser['utype']) || $aUser['utype'] != 'manager')
		{
		    Controller_Error::forbidden();
		}
    }
    
	public function index()
	{
	    $id = isset($this->params[0]) ? intval($this->params[0]) : 0;
	    if (!$id)
	    {
	        Redirect('/manager');
	    }
	    $site = new Model_Site($id);
	    $aSite = $site->getBy('id', $id);
	    $aPlaces = DB::hashedRows('SELECT * FROM places WHERE site_id = ?i', $id);
	    $aSites = DB::hashedRows('SELECT * FROM sites');
		$this->view->add(array(
		    'aSite'   => $aSite,
		    'aPlaces' => $aPlaces,
		    'aSites'  => $aSites,
		));
		return $this->view->render('manager/site/index.tpl');
	}
}